package com.example.shopping2.a_c_fragment.main.entity.greendao

import android.content.Context

class UserManager {
    var userDao: UserDao? = null
    fun setuserdao(context: Context) {
        var devOpenHelper = DaoMaster.DevOpenHelper(context, "user.db")
        var db = devOpenHelper.writableDb
        var daoMaster = DaoMaster(db)
        var newSession = daoMaster.newSession()
        userDao = newSession.userDao
    }

    fun insert(user: User) {
        userDao?.insert(user)
    }

    fun delete(id: Long) {
        var loadByRowId = userDao?.loadByRowId(id)
        if (loadByRowId != null) {
            userDao?.delete(loadByRowId)
        }
    }

    fun select(id: Long): User? {
        var loadByRowId = userDao?.loadByRowId(id)
        return loadByRowId
    }
}